package com.fxz.oauth.validation;

import com.fxz.oauth.annotation.PasswordMatch;
import com.fxz.oauth.domain.dto.UserDto;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author Fxz
 * @version 1.0
 * @date 2021-08-03 18:11
 * 固定写法 实现ConstraintValidator接口 两个泛型 第一个泛型表示作用在的自定义的注解 第二个泛型表示注解加在UserDto类上
 */
public class PasswordMatchValidator implements ConstraintValidator<PasswordMatch, UserDto> {
    /**
     * 校验的逻辑
     *
     * @param userDto
     * @param constraintValidatorContext
     * @return
     */
    @Override
    public boolean isValid(UserDto userDto, ConstraintValidatorContext constraintValidatorContext) {
        return userDto.getPassword().equals(userDto.getMatchingPassword());
    }
}
